<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button onclick="alert('哈哈哈哈');">点我</button>
    <button id="btn">点我2</button>


    <script>
        var $btn = document.querySelector('#btn');
        $btn.onclick = function() {
            alert('嘿嘿嘿');
        }
    </script>
</body>

</html>